package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.jingjiu.homeservicesapi.domain.ForumPost;
import com.jingjiu.homeservicesbiz.service.IForumPostService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 论坛帖子：记录用户发布的内容Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/system/post")
public class ForumPostController extends BaseController
{

    @Autowired
    private IForumPostService forumPostService;


    /**
     * 查询论坛帖子：记录用户发布的内容列表
     */
    @RequiresPermissions("system:post:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ForumPost forumPost)
    {
        startPage();
        List<ForumPost> list = forumPostService.selectForumPostList(forumPost);
        return getDataTable(list);
    }

    /**
     * 导出论坛帖子：记录用户发布的内容列表
     */
    @Log(title = "论坛帖子：记录用户发布的内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestBody ForumPost forumPost)
    {
        List<ForumPost> list = forumPostService.selectForumPostList(forumPost);
        ExcelUtil<ForumPost> util = new ExcelUtil<ForumPost>(ForumPost.class);
        return util.exportExcel(list, "论坛帖子：记录用户发布的内容数据");
    }



    /**
     * 新增保存论坛帖子：记录用户发布的内容
     */
    @RequiresPermissions("system:post:add")
    @Log(title = "论坛帖子：记录用户发布的内容", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody ForumPost forumPost)
    {
        return toAjax(forumPostService.insertForumPost(forumPost));
    }


    /**
     * 按id获取
     *
     * @param id   本我
     * @param mmap 内存映射
     * @return {@link ForumPost }
     */
    @RequiresPermissions("system:post:edit")
    @GetMapping("/get/{id}")
    public ForumPost getById(@PathVariable("id") Long id)
    {
        ForumPost forumPost = forumPostService.selectForumPostById(id);
       return forumPost;
    }

    /**
     * 修改保存论坛帖子：记录用户发布的内容
     */
    @RequiresPermissions("system:post:edit")
    @Log(title = "论坛帖子：记录用户发布的内容", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody ForumPost forumPost)
    {
        return toAjax(forumPostService.updateForumPost(forumPost));
    }

    /**
     * 删除论坛帖子：记录用户发布的内容
     */
    @RequiresPermissions("system:post:remove")
    @Log(title = "论坛帖子：记录用户发布的内容", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(forumPostService.deleteForumPostByIds(ids));
    }
}
